<?php
$cookie_scr_width = (isset(Yii::app()->request->cookies['screen_width'])) ? Yii::app()->request->cookies['screen_width']->value : FALSE;
$cookie_scr_height = (isset(Yii::app()->request->cookies['screen_height'])) ? Yii::app()->request->cookies['screen_height']->value : FALSE;
$cookie_post_list_height = (isset(Yii::app()->request->cookies['post_height'])) ? Yii::app()->request->cookies['post_height']->value : FALSE;
$map_start_y_pos = (isset(Yii::app()->request->cookies['map_start_y_pos'])) ? Yii::app()->request->cookies['map_start_y_pos']->value : 0;
if(!$cookie_scr_width || !$cookie_scr_height || !$cookie_post_list_height){
	Yii::app()->getClientScript()->registerCoreScript( 'jquery' );
	Yii::app()->getClientScript()->registerCoreScript( 'cookie' );
	Yii::app()->getClientScript()->registerScriptFile(
	Yii::app()->getBaseUrl(false).'/js/screensize.js',
	CClientScript::POS_END);
}
Yii::app()->getClientScript()->registerScriptFile(
Yii::app()->getBaseUrl(false).'/js/show_hide_sidebar.js',
CClientScript::POS_END);
?>
<?php

$this->breadcrumbs=array(
	'Location Postings',
);

$this->menu=array(
array('label'=>'Create LocationPosting', 'url'=>array('create')),
array('label'=>'Manage LocationPosting', 'url'=>array('admin')),
);
?>

<?php

Yii::import('ext.gmaps.*');

$gMap = new EGMap();
$gMap->setWidth($cookie_scr_width ? $cookie_scr_width : 10);
$gMap->setHeight($cookie_scr_height ? $cookie_scr_height+20 : 10);
$gMap->zoom = 12;
$mapTypeControlOptions = array(
  							'position'=> EGMapControlPosition::RIGHT_TOP,
  							'style'=>EGMap::TYPE_ROADMAP
);

$gMap->mapTypeControlOptions= $mapTypeControlOptions;
$gMap->setCenter(-6.223838, 106.866868); //Center map at Jakarta

$data = $dataProvider->getData();
foreach ($data as $posting){
	$userUpdate = $posting->User_Update;
	$username = $posting->username;
	$postingTime = $posting->posting_time;
	$type = $posting->Type;
	$latitude = $posting->latitude;
	$longitude = $posting->longitude;
	// Create GMapInfoWindows
	$info_window_a = new EGMapInfoWindow($userUpdate.' <br/>'.$postingTime.' - '. $username );
	$icon = new EGMapMarkerImage(Yii::app()->getBaseUrl(false)."/images/transjakart_green_small.png");
	if(strcasecmp($type,'transjakarta') != 0)
	{
		$icon = new EGMapMarkerImage(Yii::app()->getBaseUrl(false)."/images/krl_small.png");
	}
	$icon->setSize(24, 24);
	$icon->setAnchor(16, 16.5);
	$icon->setOrigin(0, 0);

	// Create marker
	$marker = new EGMapMarker($latitude, $longitude, array('title' => $type,'icon'=>$icon));
	$marker->addHtmlInfoWindow($info_window_a);
	$gMap->addMarker($marker);
}

// enabling marker clusterer just for fun
// to view it zoom-out the map
$gMap->enableMarkerClusterer(new EGMapMarkerClusterer());
$trafficLayer = new EGMapLayer();
$trafficLayer->setLayer(EGMapLayer::TRAFFIC);
$gMap->setLayer($trafficLayer);
$gMap->renderMap();
?>
<?php 
if($cookie_scr_width && $cookie_scr_height && $cookie_post_list_height){
//Connecting to Facebook
Yii::import('application.components.facebook.Facebook');
$facebook = new Facebook(array(
  'appId'  => Yii::app()->params->facebook_appID,
  'secret' => Yii::app()->params->facebook_appSecret,
));

?>
<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'position_posting')); ?>
<div id="posts" style="height: <?php echo ($cookie_post_list_height? $cookie_post_list_height : 0);?>px; overflow : auto; overflow-x: hidden;" >

<?php
$count = 0;
set_time_limit(0); 
foreach($posts as $post): 
?>
	<div class="post">
	<table>
		<tr>
			<td rowspan="2">
				<?php echo CHTML::image(Yii::app()->params->facebook_graphAPI.'/'.$post->username.'/picture')?>
			</td>
			<td valign="top">
		<?php
			$user = $facebook->api('/'.$post->username); 
			$user_url = CHtml::link($user['name'],$user['link'],
			 array(
			 			'id'=>'user_link_$count',
			 			'target'=>'_blank',
			 ));
			 
			echo $user_url; 
		?>
			&nbsp;di dalam
			<?php echo CHtml::link($post->Route, '#');?>
			</td>	
		</tr>
			<tr>		
			<td><?php echo $post->User_Update; ?></td>	
			</tr>
		</table>
		
	</div>
	<?php endforeach; ?>
</div>
	<?php $this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array(
    'contentSelector' => '#posts',
    'itemSelector' => 'div.post',
    'loadingText' => 'Loading...',
    'donetext' => 'Semua post telah ditampilkan.',
    'pages' => $pages,
	)); ?>
	<?php $this->endWidget();?>
<?php } //end if ?>



